import 'package:equatable/equatable.dart';
import 'package:github_client_app/service/guid_generate.dart';

// ignore: must_be_immutable
class Task extends Equatable {
  final String title;
  final String id;
  bool isDone;
  bool isDelete;

  Task({
    required this.title,
    String? id,
    this.isDone = false,
    this.isDelete = false,
  }) : id = id ?? GuidGenerate.generate();

  Task copyWith({
    String? title,
    String? id,
    bool? isDone,
    bool? isDelete,
  }) {
    return Task(
      title: title ?? this.title,
      id: id ?? this.id,
      isDone: isDone ?? this.isDone,
      isDelete: isDelete ?? this.isDelete,
    );
  }

  Map<String, dynamic> toMap() {
    return <String, dynamic>{
      'title': title,
      'isDone': isDone,
      'isDelete': isDelete,
      'id': id
    };
  }

  factory Task.fromMap(Map<String, dynamic> map) {
    return Task(
      title: map['title'] as String,
      id: map['id'] as String,
      isDone: map['isDone'] as bool,
      isDelete: map['isDelete'] as bool,
    );
  }

  @override
  List<Object?> get props => [title, isDone, isDelete, id];
}
